package com.xinhua.contaller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.xinhua.domain.Parent;
import com.xinhua.service.CityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/selectCity")
public class Contaller {

    @Resource
    private CityService cityService;

    @GetMapping
    @ResponseBody
    public String getPro(String id) throws JsonProcessingException {
        Parent parent = cityService.getparent(Integer.parseInt(id));
        System.out.println(parent);
        ObjectMapper obj = new ObjectMapper();
        String s = obj.writeValueAsString(parent);
        System.out.println(s);
        return s;
    }

}
